﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class SoftwareMore : DLL.MyWebPage
{
	private DLL.Software.View clsSoftwareView;

	protected void Page_Load(object sender, EventArgs e)
	{
		if (!IsPostBack)
		{
			ViewState["Query"] = false;
			BindGridView();
		}
	}

	protected override void OnInit(EventArgs e)
	{
		clsSoftwareView = new DLL.Software.View(Page);
		base.OnInit(e);

		Grv.RowDataBound += new GridViewRowEventHandler(Grv_RowDataBound);
		LBtnFirst.Click += new EventHandler(LBtnFirst_Click);
		LBtnForward.Click += new EventHandler(LBtnForward_Click);
		LBtnNext.Click += new EventHandler(LBtnNext_Click);
		LBtnLast.Click += new EventHandler(LBtnLast_Click);
		Grv.DataBound += new EventHandler(Grv_DataBound);
		BtnQuery.Click += new EventHandler(BtnQuery_Click);
	}

	void Grv_DataBound(object sender, EventArgs e)
	{
		GridView gv = new GridView();

		gv = (GridView)sender;

		if (gv.PageIndex == 0)
		{
			LBtnFirst.Enabled = false;
			LBtnForward.Enabled = false;
		}
		else
		{
			LBtnFirst.Enabled = true;
			LBtnForward.Enabled = true;
		}
		if (gv.PageIndex == gv.PageCount - 1)
		{
			LBtnLast.Enabled = false;
			LBtnNext.Enabled = false;
		}
		else
		{
			LBtnLast.Enabled = true;
			LBtnNext.Enabled = true;
		}
	}

	/// <summary>
	/// 最后一页
	/// </summary>
	/// <param name="sender"></param>
	/// <param name="e"></param>
	void LBtnLast_Click(object sender, EventArgs e)
	{
		Grv.PageIndex = Grv.PageCount - 1;
		BindGridView();
	}

	/// <summary>
	/// 下一页
	/// </summary>
	/// <param name="sender"></param>
	/// <param name="e"></param>
	void LBtnNext_Click(object sender, EventArgs e)
	{
		Grv.PageIndex = Grv.PageIndex + 1;
		BindGridView();
	}

	/// <summary>
	/// 上一页
	/// </summary>
	/// <param name="sender"></param>
	/// <param name="e"></param>
	void LBtnForward_Click(object sender, EventArgs e)
	{
		Grv.PageIndex = Grv.PageIndex - 1;
		BindGridView();
	}

	/// <summary>
	/// 第一页
	/// </summary>
	/// <param name="sender"></param>
	/// <param name="e"></param>
	void LBtnFirst_Click(object sender, EventArgs e)
	{
		Grv.PageIndex = 0;
		BindGridView();
	}
	void BtnQuery_Click(object sender, EventArgs e)
	{
		//Response.Write(TbQueryName.Text);
		ViewState["Query"] = true;
		BindGridView();
	}

	void Grv_RowDataBound(object sender, GridViewRowEventArgs e)
	{
		clsSoftwareView.AddLink((GridView)sender, e, 1);
	}

	private void BindGridView()
	{
		bool bQuery;

		bQuery = Convert.ToBoolean(ViewState["Query"]);
		if (bQuery)
		{
			clsSoftwareView.ShowQueryResult(Grv, TbSoftwareName.Text.Trim());
		}
		else
		{
			clsSoftwareView.ShowAll(Grv);
		}
		
	}
}